package com.jg.utils.reflex.annotate;


import com.jg.utils.reflex.annotate.en.MyAnnotation;
import com.jg.utils.reflex.annotate.en.User;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;

public class AnnotationTest {
    @Test
    public void testAnnotation(){

    Class<User> userClass = User.class;
    MyAnnotation myAnnotation = userClass.getAnnotation(MyAnnotation.class);

    if(myAnnotation!=null){
        System.out.println(myAnnotation.content() + myAnnotation.num());
    }
    }

    @Test
    public void testAnnotation2() throws IllegalAccessException {

        Class<User> userClass = User.class;
        Field[] declaredFields= userClass.getDeclaredFields();
        User user = new User();

        for (Field declardeField:declaredFields
             ) {
               MyAnnotation myAnnotation =  declardeField.getAnnotation(MyAnnotation.class);
            if(myAnnotation!=null){
               String value = myAnnotation.content();
               declardeField.setAccessible(true);
               declardeField.set(user,value);


            }

        }
        System.out.println(user);



    }
}
